package me.haoliang

/**
  * author: planck 
  * createTime: 2016/10/13.
  */
class OneInstanceScala {
  var age = 10

  private def sayHello(): Unit = {
    println("hello")
  }

}

object OneInstanceScala {
  var instance: OneInstanceScala = null

  def apply() = {
    if (instance == null) {
      this.synchronized {
        if (instance == null) {
          instance = new OneInstanceScala()
        }
      }
    }
    instance
  }

  def main(args: Array[String]): Unit = {
    OneInstanceScala().sayHello()

    val instance1 = OneInstanceScala()
    instance1.age += 1

    val instance2 = OneInstanceScala()
    instance2.age +=1

    println(instance2.age)


  }
}


